[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
                            Turbo Pascal Statements 
                           For - Repetitive Statement 

    A For statement repeatedly executes a statement while a progression of
    values is assigned to a control variable.  The control variable must
    be a variable identifier declared to be local to the block containing
    the For statement.  The control variable must be of an ordinal type and
    cannot contain any qualifiers.  The initial and final values must be
    assignment compatible with the control variable.

    The initial and final values are determined only once, upon entering
    the For statement.  The statement to be executed can be a compound
    statement.  The statement is executed once for each value in the range
    from the initial value to the final value.

    The control variable will be increased if the reserved word To is used
    in the For statement, otherwise it will be decreased if the word Downto
    is used instead.  If the initial value is greater than the final value,
    and the word To is used, the statement will not be executed.  Similarly,
    if the initial value is less than the final value and the word Downto
    is used, the statement will not be executed.


              +------------------+            +---------------+
       For  --| Control Variable |--.  :=  --.| Initial Value |----+
              +------------------+            +---------------+    |
                                                                   |
      +------------------------------------------------------------+
      |
      |--.  Downto  -+
      |              |   +-------------+            +-----------+
      |              |--.| Final Value |--.  Do  --.| statement |-.
      +--.  To  -----+   +-------------+            +-----------+


      Control Variable  :  Variable Identifier
      Initial Value     :  Expression
      Final Value       :  Expression



  EXAMPLE:  Var
               x : Integer;

            Begin
               For x := 1 To 10 Do
                  Begin
                     Write('x = ');
                     WriteLn(x);
                  End;
               For x := 10 Downto 1 Do
                  Begin
                     Write('x = ');
                     WriteLn(x);
                  End;
            End.

See Also: Ordinal
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson